home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / graftxt.com / GRAFTEX1.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-06  |  5.5 KB  |  174 lines

  1. data   segment word public
  2.        extrn   pitch:WORD     ; number of bytes per scan line
  3. data   ends
  4.  
  5. code   segment   byte public
  6. assume  cs:code,ds:data
  7. public    gtran
  8. page 60,132
  9. ;                    val val val     val      VAR    VAR
  10. ; procedure gtran(gdx,gdy,color,fontlines,fontbase,instring);
  11. ; transparent text writing
  12. ;
  13. gdx       equ  [BP+18]
  14. gdy       equ  [BP+16]
  15. color     equ  [BP+14]
  16. fontlines equ  [BP+12]
  17. fontbase  equ  [BP+8]
  18. instring  equ  [BP+4]
  19.  
  20. gtran proc    NEAR
  21.  
  22.      push      bp
  23.      mov       bp,sp
  24.      push      ds
  25.  
  26. ;
  27.  
  28.      mov     ax,pitch
  29.      mov     CS:[lpitch],ax    ; save pitch in CS: since DS is going to change
  30.  
  31. ; Calculate byte address (segment & offset) and bit mask
  32.  
  33. ;
  34.      mov     dx,040h         ; bios data segment
  35.      mov     ds,dx
  36.      mov     si,062h
  37.      mov     al,[si]         ; get active display page
  38.  
  39.      mov     dx,0A000h       ; base page of EGA/VGA memory
  40. ;
  41.      or      al,al           ; set flags
  42.      jz      page0           ; if zero, skip ofset add
  43.      add     dh,8            ; ofset to second page base of A800h
  44.  
  45. page0:
  46.      mov     ds,dx           ; DS := EGA/VGA buffer segment address
  47.  
  48.      mov     dx,3CEh         ; Graphics Controller port address
  49.      mov     ax,5
  50.      out     dx,al           ; select register 5 (mode)
  51.  
  52.      inc     dx              ; dx = 3CFh
  53.      in      al,dx           ; read current mode
  54.      and     al,0FCh
  55.      or      al,02h          ; set to mode 2
  56.      out     dx,al
  57.  
  58.      dec     dx              ; dx = 3CEh
  59.      mov     al,8
  60.      out     dx,al           ; point to bit mask register
  61.  
  62.      mov     dx,3C4h         ; Sequencer/Map Mode port address
  63.      mov     ax,0F02h
  64.      out     dx,ax           ; Select "Map Mask" register 2, enable all planes
  65.  
  66.  
  67. ;
  68.      mov     ax,gdx          ; get X address from stack frame
  69.      shr     ax,1
  70.      shr     ax,1
  71.      shr     ax,1            ; compute memory address ofset  AX := x/8
  72.      mov     bx,ax           ; save (x/8) temporarily
  73. ;
  74.      les     SI,instring     ; get doulbleword base address of string
  75.      xor     ch,ch           ; clear ch
  76.      mov     cl,byte ptr ES:[si]  ; points to length of string
  77.      or      cl,cl        ; set flags
  78.      jz         nullstring      ; if length is zero, skip everything
  79.  
  80.      mov     ax,gdy          ; get Y address (a pixel row)
  81.      add     ax,fontlines    ; add in lines in font as ofset to Y value
  82.      dec     ax              ; subtract 1 because cx is 1 based inst. of 0
  83.      mov     dx,CS:[lpitch]
  84.      mul     dx              ; AX := (y * 80)  (80 bytes per row)
  85.  
  86.      add     ax,bx           ; AX := (y * 80) + x/8          (offset)
  87.  
  88.      mov     di,ax           ; save EGA/VGA memory ofset in DI
  89.  
  90. ; Get the "Bit Mask" register address
  91.      mov     dx,3CFh         ; bit mask register
  92.  
  93.  
  94.  
  95. strloop:                     ; loop for number of characters in string
  96.      push    CX              ; save string count for outer loop
  97.      inc     SI              ; make si point to nextchar
  98.      mov     bl,byte ptr ES:[SI]      ; SI points to next char - read into bx
  99.      inc     bl              ; increment char code : draw char from bot to top
  100.      mov     ax,fontlines    ; get number of lines/char in font
  101.      mov     cx,ax           ; keep for use as char-loop counter
  102.      mul     bl              ; ax := bl (character) * al (bytes/char)
  103.      mov     bx,ax           ; leave font character ofset in BX
  104.      push    ES              ; save char string seg.
  105.      push    SI              ; save char string pointer
  106.      push    DI              ; save EGA/VGA destination
  107. ;
  108. ; loop for the number of lines
  109. ;
  110.  
  111.      les     SI,fontbase     ; get dblword base address of font
  112. ;
  113.      mov     ax,color        ; AL := pixel color value
  114.      mov     ah,al           ; AH = color value
  115. ;
  116.  
  117.  
  118. charloop:                    ; loop through the font's scanlines bottom to top
  119.  
  120.      dec     bx              ; move UP to next scanline in font
  121.  
  122.      mov     al,ES:[BX][SI]  ; get bit mask byte from font: bx=font char ofs
  123.      out     dx,al           ; load the bit mask into reg 8
  124. ;
  125. ; Set bits in the appropriate bit planes by writing color value to EGA/VGA memory
  126.  
  127.      mov     al,[di]         ; Latch the bit plane data with dummy read
  128.      mov     [di],ah         ; Set bits to '1' in appropriate planes.
  129. ;
  130.      sub     di,CS:[lpitch]         ; move up one line in EGA/VGA memory
  131.      loop    charloop        ; decrement cx and do next scanline
  132.  
  133.  
  134.  
  135.      pop     DI              ; get back EGA/VGA destination
  136.      inc     DI              ; move screen position to next char over
  137.  
  138.      pop     SI              ; pop character pointer
  139.      pop     ES              ;  "     "      segement
  140.  
  141.      pop     CX              ; get outer loop - counting chars in string
  142.      loop    strloop
  143.  
  144. nullstring:
  145. ; Restore default EGA/VGA graphics status
  146.  
  147.  
  148.  
  149.  
  150.      mov     dx,3CEh         ; Graphics Controller port address
  151.      mov     ax,5
  152.      out     dx,al           ; select register 5 (mode)
  153.  
  154.      inc     dx              ; dx = 3CFh
  155.      in      al,dx           ; read current mode
  156.      and     al,0FCh         ; set to write mode 0
  157.      out     dx,al
  158.  
  159.      dec     dx              ; dx = 3CEh
  160.      mov     ax,0FF08h        ; reset bitmask register to all on
  161.      out     dx,ax           ; ... Graphics Controller register 8
  162.  
  163.      pop       ds
  164.      pop       bp
  165.      ret       14d
  166.  
  167. lpitch  dw      0               ; local CS storage for pitch
  168.  
  169. gtran endp
  170.  
  171. code ends
  172.  
  173.      end
  174.